
package com.sausageking.client;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import com.sausageking.shared.Checkin;
import com.sausageking.shared.BuyerException;
import com.sausageking.shared.Merchant;
import com.sausageking.shared.Redemption;
import com.sausageking.shared.Consumer;

@RemoteServiceRelativePath("consumer")
public interface ConsumerService extends RemoteService {

  public enum AuthType {
    PASSWORD, TOKEN
  }

  Checkin stamp(String email, String merchantId, String merchantCode)
      throws BuyerException;

  RedeemResponse redeem(String email, String merchantId, AuthType authType,
      String secret) throws BuyerException;

  MerchantCustomerInfo getMerchantCustomerInfo(String userId, String merchantId)
      throws BuyerException;

  String signIn(String email, String password) throws BuyerException;

  String signUp(String email, String password) throws BuyerException;

  public static class RedeemResponse implements Serializable {

    private static final long serialVersionUID = 1228885709758192194L;

    private Redemption redemption;

    private String newSessionId;

    public RedeemResponse() {
    };

    public RedeemResponse(Redemption redemption, String newSessionId) {
      this.redemption = redemption;
      this.newSessionId = newSessionId;
    }

    public Redemption getRedemption() {
      return redemption;
    }

    public String getNewSessionId() {
      return newSessionId;
    }

  }

  public static class MerchantCustomerInfo implements Serializable {

    private static final long serialVersionUID = -3877794365025086123L;

    public Merchant getMerchant() {
      return merchant;
    }

    public MerchantCustomerInfo setMerchant(Merchant merchant) {
      this.merchant = merchant;
      return this;
    }

    public Consumer getUser() {
      return user;
    }

    public MerchantCustomerInfo setUser(Consumer user) {
      this.user = user;
      return this;
    }

    public List<Checkin> getCheckins() {
      return checkins;
    }

    public List<Redemption> getRedemptons() {
      return redemptions;
    }

    public MerchantCustomerInfo setCheckins(List<Checkin> checkins) {
      this.checkins = checkins;
      return this;
    }

    public MerchantCustomerInfo setRedemptions(List<Redemption> redemptions) {
      this.redemptions = redemptions;
      return this;
    }

    private Merchant merchant;

    private Consumer user;

    private List<Checkin> checkins = new ArrayList<Checkin>();

    private List<Redemption> redemptions = new ArrayList<Redemption>();

    public String toString() {
      ToStringHelper helper = Objects.toStringHelper(this);
      if (merchant != null) {
        helper.add("merchant", merchant.toString());
      }
      if (user != null) {
        helper.add("user", user.toString());
      }
      if (checkins != null) {
        for (Checkin checkin : checkins) {
          helper.add("checkin", checkin.toString());
        }
      }
      if (redemptions != null) {
        for (Redemption redemption : redemptions) {
          helper.add("redemption", redemption);
        }
      }
      return helper.toString();
    }
  }
}
